﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using SGLisp;

public static class MapTableMgr
{
    public static Hashtable BlockTable;
    public static Hashtable MapIndexTable;
    static Dictionary<int, object> Maps = new Dictionary<int, object>();
    public static string MapPath;
    public static void LoadFromFile(string mapPath,Context context)
    {
        BlockTable = (Hashtable)Helper.EvalValueFromFile(mapPath + "/Blocks.clj",context);
        MapIndexTable = (Hashtable)Helper.EvalValueFromFile(mapPath + "/Maps.clj", context);
        MapPath = mapPath;
    }

    public static object GetMapByIndex(int id)
    {
        if (!Maps.ContainsKey(id))
        {
            Hashtable mapIndex = (Hashtable)MapIndexTable[id];
            string TablePath = (string)mapIndex[":map-path"];
            Maps[id] = Helper.EvalValueFromFile(MapPath + "/" + TablePath, RT.MainContext);
        }
        return Maps[id];
    }

}